﻿using Bomber.TF.GameCenter.BlockCenter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bomber.TF.GameCenter.MapCenter
{
    [Species(SpeciesType.Map1)]
    public class MapOne : MapBase
    {
        public MapOne(int row, int column, int mapWidth, int mapHeight, int cellWidth, int cellHeight)
            : base(row, column, mapWidth, mapHeight, cellWidth, cellHeight, SpeciesType.Map1)
        {

        }
        public override unsafe void CreateTool(GameListBase* set)
        {
            var destroyBlocks= _blockBases.Where(t => t.SpeciesType == SpeciesType.DestroyBlock).ToList();
            int count = destroyBlocks.Count >> 1;
            int scount = count >> 1;
            int bombCount = count - scount;
            Random random = new Random();
            for (int i = 0; i < count; i++)
            {
                var first = destroyBlocks[random.Next(0, destroyBlocks.Count)];
                DestroyBlock? destroy = first as DestroyBlock;
                destroy.ToolType = CreateTool(ref scount,ref bombCount);
                destroyBlocks.Remove(first);
            }
        }
        protected SpeciesType CreateTool(ref int scount, ref int bombCount)
        {
            if (scount-- > 0)
                return SpeciesType.SalamanderTool;
            if(bombCount-- > 0)
                return SpeciesType.BombTool;

            return SpeciesType.None;
        }
        public override void Draw(Graphics graphics)
        {
            // 绘制背景
            graphics.FillRectangle(Brushes.Green, new Rectangle(StartX, StartY, Size.Width, Size.Height));
        }

        protected override void InitMap()
        {
            base.InitMap();
            for (int j = 1; j < MaxRow - 1; j++)
            {
                if ((j & 1) == 1) continue;
                for (int i = 1; i < MaxColumn - 1; i++)
                {
                    if ((i & 1) == 1) continue;
                    this.AddBlock(new HardBlock(CellWidth, CellHeight), j, i);
                }
            }
            // 第一行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 8);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 9);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 9);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 12);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 15);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 17);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 1, 18);
            // 第二行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 2, 3);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 2, 7);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 2, 9);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 2, 21);
            // 第三行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 2);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 7);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 9);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 10);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 11);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 18);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 3, 20);
            // 第四行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 4, 1);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 4, 3);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 4, 11);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 4, 13);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 4, 15);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 4, 19);
            // 第五行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 5, 10);
            // 第六行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 6, 3);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 6, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 6, 11);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 6, 17);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 6, 19);
            // 第七行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 1);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 2);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 7);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 8);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 12);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 13);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 14);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 19);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 20);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 7, 21);
            // 第八行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 8, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 8, 9);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 8, 11);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 8, 17);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 8, 19);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 8, 21);
            // 第九行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 1);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 2);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 3);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 6);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 12);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 14);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 15);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 9, 19);
            // 第十行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 10, 1);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 10, 3);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 10, 7);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 10, 9);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 10, 11);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 10, 17);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 10, 21);
            // 第十一行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 11, 4);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 11, 6);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 11, 8);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 11, 13);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 11, 14);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 11, 18);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 11, 20);
            // 第十二行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 12, 1);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 12, 3);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 12, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 12, 7);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 12, 11);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 12, 13);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 12, 19);
            // 第十三行
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 13, 5);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 13, 6);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 13, 7);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 13, 13);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 13, 14);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 13, 18);
            this.AddBlock(new DestroyBlock(CellWidth, CellHeight), 13, 19);
        }
    }
}
